var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
    })(e, t);
}, function(e, t) {
    function i() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (i.prototype = t.prototype, 
    new i());
});

Object.defineProperty(n, "__esModule", {
    value: !0
});

var a = e("AudioManager"), r = e("PlayerModel"), s = e("Global"), c = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.speed = null, e.count = 0, e.time = 0, e.min = 0, e.chargeTime = 0, e.chargeTotalTime = 2, 
        e.skeletonFire = null, e.skeletonHurt = null, e.spriteBullet = null, e.root = null, 
        e.tween = null, e.isDestory = !1, e;
    }
    return i(e, t), e.prototype.doDestory = function() {
        try {
            this.speed = null, this.count = 0, this.chargeTime = 0, this.time = 0, this.min = 0, 
            this.isDestory = !0, this.isSkill = !1, this.tween && (this.tween.stop(), this.tween = null), 
            this.skeletonFire && this.player.gameView.removeSkeleton(this.skeletonFire.node), 
            this.skeletonHurt && this.player.gameView.removeSkeleton(this.skeletonHurt.node), 
            this.spriteBullet && this.player.gameView.removeSprite(this.spriteBullet.node), 
            this.skeletonFire = null, this.skeletonHurt = null, this.spriteBullet = null, this.root && (this.root.destroy(), 
            this.root = null);
        } catch (e) {}
    }, e.prototype.doUpdate = function(e) {
        this.player && !this.isSkill && (this.player.model.hasBuffer(r.BufferType.蓄力) ? this.chargeTime < this.chargeTotalTime && (this.chargeTime += e, 
        this.chargeTime >= this.chargeTotalTime && this.player.playEffectSkill()) : this.chargeTime = 0);
    }, e.prototype.doSkill = function(e) {
        var t = this;
        if (this.chargeTime < this.chargeTotalTime) return this.doDestory(), !0;
        try {
            this.speed = e.dir.mul(e.model.MOV), this.isSkill = !0, this.isDestory = !1, null == this.root && (this.root = new cc.Node()), 
            this.root.zIndex = 100, this.root.angle = cc.misc.radiansToDegrees(Math.atan2(e.dir.y, e.dir.x)), 
            this.root.setPosition(e.pos), this.root.setParent(this.player.node.parent);
            var o = this.player;
            o.gameView.appendSkeleton({
                url: "skeleton/game/fire激光枪4/skeleton",
                root: this.root,
                pos: cc.Vec2.ZERO
            }).then(function(e) {
                t.isDestory ? o.gameView.removeSkeleton(e.node) : (t.skeletonFire = e, t.skeletonFire.setAnimation(0, "jiguangqiang1", !0), 
				t.skeletonFire.premultipliedAlpha = false,
                t.skeletonFire.node.setScale(1.2), t.skeletonFire.node.zIndex = 2);
            }), o.gameView.appendSprite({
                url: "texture/bullet/33",
                root: this.root,
                pos: cc.Vec2.ZERO
            }).then(function(e) {
                t.isDestory ? e && o.gameView.removeSprite(e.node) : (t.spriteBullet = e, t.spriteBullet.node.height = 0, 
                t.spriteBullet.node.angle = 90, cc.tween(t.spriteBullet.node).repeatForever(cc.tween().to(.2, {
                    scaleX: .7
                }).to(.2, {
                    scaleX: 1
                })).start());
            }), o.gameView.appendSkeleton({
                url: "skeleton/game/hurt激光枪4/skeleton",
                root: this.root,
                pos: cc.Vec2.ZERO
            }).then(function(e) {
                t.isDestory ? o.gameView.removeSkeleton(e.node) : (t.skeletonHurt = e, t.skeletonHurt.setAnimation(0, "jiguangqiang2", !0), 
                t.skeletonHurt.node.setScale(1.2), t.skeletonHurt.node.zIndex = 1, t.skeletonHurt.node.opacity = 0);
            }), o.model.addBuffer(r.BufferType.固定), cc.tween(o.node).delay(.05 * this.config.options.num).call(function() {
                o.model.removeBuffer(r.BufferType.固定);
            }).start(), a.default.getInstance().playAudio("技能激光枪"), this.tween = cc.tween(o.node).repeat(this.config.options.num, cc.tween().delay(.05).call(function() {
                t.doExecute(e);
            })).call(function() {
                t.doDestory();
            }).start();
        } catch (e) {}
        return !1;
    }, e.prototype.doLaser = function(t, o) {
        var i = this;
        void 0 === t && (t = 30);
        try {
            if (this.player.model.isDead()) this.doDestory(); else {
                for (var e = this.player.gameView.astar.retrieve(s.G.getRectByVec(o.pos, this.speed.mul(this.time), 0)).filter(function(e) {
                    return (e.isCanBlock(o.model.type) || e.isCanAttacked(o.model.type)) && cc.Intersection.pointLineDistance(e.node.getPosition(), o.pos, o.pos.add(i.speed.mul(i.time)), !0) < t;
                }).sort(function(e, t) {
                    return e.node.getPosition().sub(o.pos).mag() - t.node.getPosition().sub(o.pos).mag();
                }), n = this.speed.mul(this.time).mag(), r = 0; r < e.length; r++) {
                    var l = e[r];
                    if (l.isCanBlock(o.model.type)) {
                        if (!l.isCanAttacked(o.model.type)) {
                            n = l.node.getPosition().sub(o.pos).mag();
                            break;
                        }
                        if (!l.doHurt(o.model, o.dir)) {
                            n = l.node.getPosition().sub(o.pos).mag();
                            break;
                        }
                    } else l.isCanAttacked(o.model.type) && l.doHurt(o.model, o.dir);
                }
                n > this.min && (this.min = n), this.player.gameView.players.forEach(function(e) {
                    e && e.checkTarget(e) && e.canHurt() && e.model.group != o.model.group && e.node.getPosition().sub(o.pos).mag() < i.min && cc.Intersection.pointLineDistance(e.node.getPosition(), o.pos, o.pos.add(i.speed.mul(i.time)), !0) < t && e.doHurt(o.model, o.dir);
                });
                var a = 0 == e.length ? this.speed.mul(this.time).mag() : this.min - 40;
                this.spriteBullet ? (this.spriteBullet.node.active = !0, this.spriteBullet.node.anchorY = 1, 
                this.spriteBullet.node.height = a, this.spriteBullet.node.width = t) : cc.log("激光sprite不存在"), 
                this.skeletonHurt && (this.skeletonHurt.node.setPosition(cc.v2(a, 0)), this.skeletonHurt.node.opacity = 255);
            }
        } catch (e) {
            cc.error(e);
        }
    }, e.prototype.doExecute = function(e) {
        this.time += .05, this.doLaser(104, e);
    }, e;
}(e("SkillBase").default);

n.default = c;